﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;

namespace WartburgInfo
{
    public partial class Menu : Form
    {
        public Menu()
        {
            InitializeComponent();
        }


        private void Menu_Load(object sender, EventArgs e)
        {
            if (File.Exists(Application.StartupPath + @"\inloginfo.dat"))
            {
                using (StreamReader openLogindata = new StreamReader(Application.StartupPath + @"\inloginfo.dat"))
                {
                    inlogInfo.username = openLogindata.ReadLine();
                    inlogInfo.password = openLogindata.ReadLine();
                }
            }
            else
            {             
                    using (loginInfo openLoginForm = new loginInfo())
                    {
                        if (openLoginForm.ShowDialog() == DialogResult.OK)
                        {
                        }
                    }
            }
        }

        private void btnHuiswerk_Click(object sender, EventArgs e)
        {
            using (Huiswerk huiswerk = new Huiswerk())
            {
                huiswerk.ShowDialog();
            }
        }

        private void brnCijfers_Click(object sender, EventArgs e)
        {
            using (Cijfers cijfers = new Cijfers())
            {
                cijfers.ShowDialog();
            }
        }

        private void btnRooster_Click(object sender, EventArgs e)
        {
            using (Rooster rooster = new Rooster())
            {
                rooster.ShowDialog();
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Visible = false;
            File.Delete(Application.StartupPath + @"\inloginfo.dat");
            inlogInfo.username = "";
            inlogInfo.password = "";
            using (WebBrowser logOut = new WebBrowser())
            {
                logOut.Navigate(@"https://leerlingen.wartburg.nl/Page/nctrue/sp2281/action=logout/Index.html");
            }
            using (loginInfo openLoginForm = new loginInfo())
            {
                if (openLoginForm.ShowDialog() == DialogResult.OK)
                {
                    
                }
            }
            Visible = true;
        }

        private void Menu_Activated(object sender, EventArgs e)
        {
            if (File.Exists(Application.StartupPath + @"\inloginfo.dat"))
            {
                using (StreamReader openLogindata = new StreamReader(Application.StartupPath + @"\inloginfo.dat"))
                {
                    inlogInfo.username = openLogindata.ReadLine();
                    inlogInfo.password = openLogindata.ReadLine();
                }
            }
            else
            {
                if (inlogInfo.username.Length == 0)
                {
                    Visible = false;
                    using (loginInfo openLoginForm = new loginInfo())
                    {
                        if (openLoginForm.ShowDialog() == DialogResult.OK)
                        {
                        }
                    }
                    Visible = true;
                }
            }
        }

    }
}
